package com.evildog.workspace.invest.application.controller;

import com.evildog.workspace.common.result.Result;
import com.evildog.workspace.common.result.ResultGenerator;
import com.evildog.workspace.dependencies.mybatis.util.QueryConditionUtils;
import com.evildog.workspace.invest.application.bo.BillBO;
import com.evildog.workspace.invest.application.bo.BillListBO;
import com.evildog.workspace.invest.application.convert.BillConvert;
import com.evildog.workspace.invest.application.model.BillListParam;
import com.evildog.workspace.invest.application.model.BillParam;
import com.evildog.workspace.invest.application.service.BillService;
import com.evildog.workspace.invest.application.vo.BillListVO;
import com.evildog.workspace.invest.application.vo.BillVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * bill Controller
    账单
 * </p>
 *
 * @author evildog
 * @since 2020-08-06
 */
@RestController
@RequestMapping("/bills")
@AllArgsConstructor
@Api(tags = "bill相关接口")
public class BillController {

    private BillService billService;

    @PostMapping
    @ApiOperation(value = "添加接口")
    public Result<Boolean> save(@RequestBody BillParam billParam) {
        return ResultGenerator.status(billService.save(BillConvert.INSTANCE.convert(billParam)));
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除接口")
    public Result<Boolean> removeById(@PathVariable("id") Long id) {
        return ResultGenerator.status(billService.removeById(id));
    }

    @PutMapping("/{id}")
    @ApiOperation(value = "更新接口")
    public Result<Boolean> updateById(@PathVariable("id") Long id,@RequestBody BillParam billParam) {
        return ResultGenerator.status(billService.updateById(id, BillConvert.INSTANCE.convert(billParam)));
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "查询详情接口")
    public Result<BillVO> getById(@PathVariable("id") Long id) {
        BillBO billBO = billService.getDetailById(id);
        return ResultGenerator.success(BillConvert.INSTANCE.convert(billBO));
    }

    @GetMapping
    @ApiOperation(value = "表List查询接口")
    public Result<List<BillListVO>> getList(BillListParam billListParam){
        List<BillListBO> billListBO = billService.getList(
                        QueryConditionUtils.getQueryCondition(billListParam),
                        BillConvert.INSTANCE.convert(billListParam));
        return ResultGenerator.success(BillConvert.INSTANCE.convertVoList(billListBO));
    }

}